{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Python Matrix"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "# Numpy Library\n",
        "import numpy as np # for matrix and linear algebra"
      ],
      "outputs": [],
      "execution_count": 5,
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "# yfinance is used to fetch data \n",
        "import yfinance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AMD'\n",
        "start = '2018-01-01'\n",
        "end = '2018-01-31'\n",
        "\n",
        "# Read data \n",
        "dataset = yf.download(symbol,start,end)\n",
        "\n",
        "# View Columns\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 10,
          "data": {
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2018-01-02</th>\n      <td>10.42</td>\n      <td>11.02</td>\n      <td>10.34</td>\n      <td>10.98</td>\n      <td>10.98</td>\n      <td>44146300</td>\n    </tr>\n    <tr>\n      <th>2018-01-03</th>\n      <td>11.61</td>\n      <td>12.14</td>\n      <td>11.36</td>\n      <td>11.55</td>\n      <td>11.55</td>\n      <td>154066700</td>\n    </tr>\n    <tr>\n      <th>2018-01-04</th>\n      <td>12.10</td>\n      <td>12.43</td>\n      <td>11.97</td>\n      <td>12.12</td>\n      <td>12.12</td>\n      <td>109503000</td>\n    </tr>\n    <tr>\n      <th>2018-01-05</th>\n      <td>12.19</td>\n      <td>12.22</td>\n      <td>11.66</td>\n      <td>11.88</td>\n      <td>11.88</td>\n      <td>63808900</td>\n    </tr>\n    <tr>\n      <th>2018-01-08</th>\n      <td>12.01</td>\n      <td>12.30</td>\n      <td>11.85</td>\n      <td>12.28</td>\n      <td>12.28</td>\n      <td>63346000</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
            "text/plain": "             Open   High    Low  Close  Adj Close     Volume\nDate                                                        \n2018-01-02  10.42  11.02  10.34  10.98      10.98   44146300\n2018-01-03  11.61  12.14  11.36  11.55      11.55  154066700\n2018-01-04  12.10  12.43  11.97  12.12      12.12  109503000\n2018-01-05  12.19  12.22  11.66  11.88      11.88   63808900\n2018-01-08  12.01  12.30  11.85  12.28      12.28   63346000"
          },
          "metadata": {}
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df = dataset.drop(['High', 'Low', 'Close', 'Volume'], axis=1)"
      ],
      "outputs": [],
      "execution_count": 12,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "df.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 14,
          "data": {
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>Adj Close</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2018-01-02</th>\n      <td>10.42</td>\n      <td>10.98</td>\n    </tr>\n    <tr>\n      <th>2018-01-03</th>\n      <td>11.61</td>\n      <td>11.55</td>\n    </tr>\n    <tr>\n      <th>2018-01-04</th>\n      <td>12.10</td>\n      <td>12.12</td>\n    </tr>\n    <tr>\n      <th>2018-01-05</th>\n      <td>12.19</td>\n      <td>11.88</td>\n    </tr>\n    <tr>\n      <th>2018-01-08</th>\n      <td>12.01</td>\n      <td>12.28</td>\n    </tr>\n  </tbody>\n</table>\n</div>",
            "text/plain": "             Open  Adj Close\nDate                        \n2018-01-02  10.42      10.98\n2018-01-03  11.61      11.55\n2018-01-04  12.10      12.12\n2018-01-05  12.19      11.88\n2018-01-08  12.01      12.28"
          },
          "metadata": {}
        }
      ],
      "execution_count": 14,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "A = np.array(df)\n",
        "A"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 13,
          "data": {
            "text/plain": "array([[ 10.42,  10.98],\n       [ 11.61,  11.55],\n       [ 12.1 ,  12.12],\n       [ 12.19,  11.88],\n       [ 12.01,  12.28],\n       [ 12.  ,  11.82],\n       [ 11.63,  11.96],\n       [ 12.07,  12.14],\n       [ 11.82,  12.02],\n       [ 12.05,  11.91],\n       [ 11.9 ,  12.18],\n       [ 12.18,  12.47],\n       [ 12.56,  12.59],\n       [ 12.61,  12.65],\n       [ 12.82,  12.94],\n       [ 13.02,  12.71],\n       [ 12.78,  12.41],\n       [ 12.7 ,  12.95],\n       [ 13.13,  13.32],\n       [ 13.12,  12.87],\n       [ 13.24,  13.74]])"
          },
          "metadata": {}
        }
      ],
      "execution_count": 13,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(\"A =\", A) \n",
        "print(\"A[1] =\", A[1])      # 2nd row\n",
        "print(\"A[1][2] =\", A[1][1])   # 2nd element of 2nd row\n",
        "print(\"A[0][-1] =\", A[0][-1]) "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "A = [[ 10.42  10.98]\n",
            " [ 11.61  11.55]\n",
            " [ 12.1   12.12]\n",
            " [ 12.19  11.88]\n",
            " [ 12.01  12.28]\n",
            " [ 12.    11.82]\n",
            " [ 11.63  11.96]\n",
            " [ 12.07  12.14]\n",
            " [ 11.82  12.02]\n",
            " [ 12.05  11.91]\n",
            " [ 11.9   12.18]\n",
            " [ 12.18  12.47]\n",
            " [ 12.56  12.59]\n",
            " [ 12.61  12.65]\n",
            " [ 12.82  12.94]\n",
            " [ 13.02  12.71]\n",
            " [ 12.78  12.41]\n",
            " [ 12.7   12.95]\n",
            " [ 13.13  13.32]\n",
            " [ 13.12  12.87]\n",
            " [ 13.24  13.74]]\n",
            "A[1] = [ 11.61  11.55]\n",
            "A[1][2] = 11.55\n",
            "A[0][-1] = 10.98\n"
          ]
        }
      ],
      "execution_count": 16,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "column = [];        # empty list\n",
        "for row in A:\n",
        "  column.append(row[1]) \n",
        "\n",
        "print(\"Second column =\", column)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Second column = [10.98, 11.550000000000001, 12.119999999999999, 11.880000000000001, 12.279999999999999, 11.82, 11.960000000000001, 12.140000000000001, 12.02, 11.91, 12.18, 12.470000000000001, 12.59, 12.65, 12.94, 12.710000000000001, 12.41, 12.949999999999999, 13.32, 12.869999999999999, 13.74]\n"
          ]
        }
      ],
      "execution_count": 19,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "type(A)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 20,
          "data": {
            "text/plain": "numpy.ndarray"
          },
          "metadata": {}
        }
      ],
      "execution_count": 20,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Example of arange and shape()\n",
        "A = np.arange(4)\n",
        "print('A =', A)\n",
        "\n",
        "B = np.arange(12).reshape(2, 6)\n",
        "print('B =', B)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "A = [0 1 2 3]\n",
            "B = [[ 0  1  2  3  4  5]\n",
            " [ 6  7  8  9 10 11]]\n"
          ]
        }
      ],
      "execution_count": 41,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "A = np.array(dataset['High'], dataset['Low'])\n",
        "B = np.array(dataset['Open'], dataset['Close'])"
      ],
      "outputs": [],
      "execution_count": 42,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "C = A + B\n",
        "print(\"Addition Matrix: \\n\", C)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Addition Matrix: \n",
            " [ 21.44  23.75  24.53  24.41  24.31  24.02  23.78  24.26  23.89  24.25\n",
            "  24.09  24.86  25.44  25.35  25.82  26.07  25.72  25.65  26.6   26.39\n",
            "  27.09]\n"
          ]
        }
      ],
      "execution_count": 47,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "D = A - B\n",
        "print(\"Subtraction Matrix: \\n\", D)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Subtraction Matrix: \n",
            " [ 0.6   0.53  0.33  0.03  0.29  0.02  0.52  0.12  0.25  0.15  0.29  0.5\n",
            "  0.32  0.13  0.18  0.03  0.16  0.25  0.34  0.15  0.61]\n"
          ]
        }
      ],
      "execution_count": 48,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Multiplication of Two Matrices\n",
        "E = A.dot(B)\n",
        "print(\"Multiplication of Two Matrices: \\n\", E)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Multiplication of Two Matrices: \n",
            " 3247.8911\n"
          ]
        }
      ],
      "execution_count": 49,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "T = A.transpose()\n",
        "print(\"Transpose of a Matrix: \\n\", T)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Transpose of a Matrix: \n",
            " [ 11.02  12.14  12.43  12.22  12.3   12.02  12.15  12.19  12.07  12.2\n",
            "  12.19  12.68  12.88  12.74  13.    13.05  12.94  12.95  13.47  13.27\n",
            "  13.85]\n"
          ]
        }
      ],
      "execution_count": 50,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Access matrix elements, rows, and columns\n",
        "\n",
        "print(\"A[0] =\", A[0])     # First element     \n",
        "print(\"A[2] =\", A[2])     # Third element \n",
        "print(\"A[-1] =\", A[-1])   # Last element    "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "A[0] = 11.02\n",
            "A[2] = 12.43\n",
            "A[-1] = 13.85\n"
          ]
        }
      ],
      "execution_count": 51,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "A = np.array(dataset[['Open', 'Low', 'High', 'Close']])\n",
        "\n",
        "print(\"Matrix of A: \\n\", A)\n",
        "#  First element of first row\n",
        "print(\"A[0][0] =\", A[0][0])  \n",
        "\n",
        "# Third element of second row\n",
        "print(\"A[1][2] =\", A[1][2])\n",
        "\n",
        "# Last element of last row\n",
        "print(\"A[-1][-1] =\", A[-1][-1])  "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Matrix of A: \n",
            " [[ 10.42  10.34  11.02  10.98]\n",
            " [ 11.61  11.36  12.14  11.55]\n",
            " [ 12.1   11.97  12.43  12.12]\n",
            " [ 12.19  11.66  12.22  11.88]\n",
            " [ 12.01  11.85  12.3   12.28]\n",
            " [ 12.    11.71  12.02  11.82]\n",
            " [ 11.63  11.56  12.15  11.96]\n",
            " [ 12.07  11.9   12.19  12.14]\n",
            " [ 11.82  11.8   12.07  12.02]\n",
            " [ 12.05  11.8   12.2   11.91]\n",
            " [ 11.9   11.82  12.19  12.18]\n",
            " [ 12.18  12.15  12.68  12.47]\n",
            " [ 12.56  12.54  12.88  12.59]\n",
            " [ 12.61  12.37  12.74  12.65]\n",
            " [ 12.82  12.76  13.    12.94]\n",
            " [ 13.02  12.6   13.05  12.71]\n",
            " [ 12.78  12.32  12.94  12.41]\n",
            " [ 12.7   12.62  12.95  12.95]\n",
            " [ 13.13  13.05  13.47  13.32]\n",
            " [ 13.12  12.69  13.27  12.87]\n",
            " [ 13.24  13.15  13.85  13.74]]\n",
            "A[0][0] = 10.42\n",
            "A[1][2] = 12.14\n",
            "A[-1][-1] = 13.74\n"
          ]
        }
      ],
      "execution_count": 59,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Access rows of a Matrix\n",
        "\n",
        "print(\"A[0] =\", A[0]) # First Row\n",
        "print(\"A[2] =\", A[2]) # Third Row\n",
        "print(\"A[-1] =\", A[-1]) # Last Row (3rd row in this case)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "A[0] = [ 10.42  10.34  11.02  10.98]\n",
            "A[2] = [ 12.1   11.97  12.43  12.12]\n",
            "A[-1] = [ 13.24  13.15  13.85  13.74]\n"
          ]
        }
      ],
      "execution_count": 60,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Access columns of a Matrix\n",
        "\n",
        "print(\"A[:,0] =\",A[:,0]) # First Column\n",
        "print(\"A[:,3] =\", A[:,3]) # Fourth Column\n",
        "print(\"A[:,-1] =\", A[:,-1]) # Last Column (4th column in this case)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "A[:,0] = [ 10.42  11.61  12.1   12.19  12.01  12.    11.63  12.07  11.82  12.05\n",
            "  11.9   12.18  12.56  12.61  12.82  13.02  12.78  12.7   13.13  13.12\n",
            "  13.24]\n",
            "A[:,3] = [ 10.98  11.55  12.12  11.88  12.28  11.82  11.96  12.14  12.02  11.91\n",
            "  12.18  12.47  12.59  12.65  12.94  12.71  12.41  12.95  13.32  12.87\n",
            "  13.74]\n",
            "A[:,-1] = [ 10.98  11.55  12.12  11.88  12.28  11.82  11.96  12.14  12.02  11.91\n",
            "  12.18  12.47  12.59  12.65  12.94  12.71  12.41  12.95  13.32  12.87\n",
            "  13.74]\n"
          ]
        }
      ],
      "execution_count": 61,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# 3rd to 5th elements\n",
        "print(A[2:5])        "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 12.1   11.97  12.43  12.12]\n",
            " [ 12.19  11.66  12.22  11.88]\n",
            " [ 12.01  11.85  12.3   12.28]]\n"
          ]
        }
      ],
      "execution_count": 63,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# 1st to 4th elements\n",
        "print(A[:-5])        "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 10.42  10.34  11.02  10.98]\n",
            " [ 11.61  11.36  12.14  11.55]\n",
            " [ 12.1   11.97  12.43  12.12]\n",
            " [ 12.19  11.66  12.22  11.88]\n",
            " [ 12.01  11.85  12.3   12.28]\n",
            " [ 12.    11.71  12.02  11.82]\n",
            " [ 11.63  11.56  12.15  11.96]\n",
            " [ 12.07  11.9   12.19  12.14]\n",
            " [ 11.82  11.8   12.07  12.02]\n",
            " [ 12.05  11.8   12.2   11.91]\n",
            " [ 11.9   11.82  12.19  12.18]\n",
            " [ 12.18  12.15  12.68  12.47]\n",
            " [ 12.56  12.54  12.88  12.59]\n",
            " [ 12.61  12.37  12.74  12.65]\n",
            " [ 12.82  12.76  13.    12.94]\n",
            " [ 13.02  12.6   13.05  12.71]]\n"
          ]
        }
      ],
      "execution_count": 64,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# 6th to last elements\n",
        "print(A[5:])    "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 12.    11.71  12.02  11.82]\n",
            " [ 11.63  11.56  12.15  11.96]\n",
            " [ 12.07  11.9   12.19  12.14]\n",
            " [ 11.82  11.8   12.07  12.02]\n",
            " [ 12.05  11.8   12.2   11.91]\n",
            " [ 11.9   11.82  12.19  12.18]\n",
            " [ 12.18  12.15  12.68  12.47]\n",
            " [ 12.56  12.54  12.88  12.59]\n",
            " [ 12.61  12.37  12.74  12.65]\n",
            " [ 12.82  12.76  13.    12.94]\n",
            " [ 13.02  12.6   13.05  12.71]\n",
            " [ 12.78  12.32  12.94  12.41]\n",
            " [ 12.7   12.62  12.95  12.95]\n",
            " [ 13.13  13.05  13.47  13.32]\n",
            " [ 13.12  12.69  13.27  12.87]\n",
            " [ 13.24  13.15  13.85  13.74]]\n"
          ]
        }
      ],
      "execution_count": 65,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# 1st to last elements\n",
        "print(A[:])    "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 10.42  10.34  11.02  10.98]\n",
            " [ 11.61  11.36  12.14  11.55]\n",
            " [ 12.1   11.97  12.43  12.12]\n",
            " [ 12.19  11.66  12.22  11.88]\n",
            " [ 12.01  11.85  12.3   12.28]\n",
            " [ 12.    11.71  12.02  11.82]\n",
            " [ 11.63  11.56  12.15  11.96]\n",
            " [ 12.07  11.9   12.19  12.14]\n",
            " [ 11.82  11.8   12.07  12.02]\n",
            " [ 12.05  11.8   12.2   11.91]\n",
            " [ 11.9   11.82  12.19  12.18]\n",
            " [ 12.18  12.15  12.68  12.47]\n",
            " [ 12.56  12.54  12.88  12.59]\n",
            " [ 12.61  12.37  12.74  12.65]\n",
            " [ 12.82  12.76  13.    12.94]\n",
            " [ 13.02  12.6   13.05  12.71]\n",
            " [ 12.78  12.32  12.94  12.41]\n",
            " [ 12.7   12.62  12.95  12.95]\n",
            " [ 13.13  13.05  13.47  13.32]\n",
            " [ 13.12  12.69  13.27  12.87]\n",
            " [ 13.24  13.15  13.85  13.74]]\n"
          ]
        }
      ],
      "execution_count": 66,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# reversing a list\n",
        "print(A[::-1])     "
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 13.24  13.15  13.85  13.74]\n",
            " [ 13.12  12.69  13.27  12.87]\n",
            " [ 13.13  13.05  13.47  13.32]\n",
            " [ 12.7   12.62  12.95  12.95]\n",
            " [ 12.78  12.32  12.94  12.41]\n",
            " [ 13.02  12.6   13.05  12.71]\n",
            " [ 12.82  12.76  13.    12.94]\n",
            " [ 12.61  12.37  12.74  12.65]\n",
            " [ 12.56  12.54  12.88  12.59]\n",
            " [ 12.18  12.15  12.68  12.47]\n",
            " [ 11.9   11.82  12.19  12.18]\n",
            " [ 12.05  11.8   12.2   11.91]\n",
            " [ 11.82  11.8   12.07  12.02]\n",
            " [ 12.07  11.9   12.19  12.14]\n",
            " [ 11.63  11.56  12.15  11.96]\n",
            " [ 12.    11.71  12.02  11.82]\n",
            " [ 12.01  11.85  12.3   12.28]\n",
            " [ 12.19  11.66  12.22  11.88]\n",
            " [ 12.1   11.97  12.43  12.12]\n",
            " [ 11.61  11.36  12.14  11.55]\n",
            " [ 10.42  10.34  11.02  10.98]]\n"
          ]
        }
      ],
      "execution_count": 67,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(A[:2, :4])  # two rows, four columns"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 10.42  10.34  11.02  10.98]\n",
            " [ 11.61  11.36  12.14  11.55]]\n"
          ]
        }
      ],
      "execution_count": 68,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(A[:1,])  # first row, all columns"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 10.42  10.34  11.02  10.98]]\n"
          ]
        }
      ],
      "execution_count": 69,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(A[:,2])  # all rows, second column"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ 11.02  12.14  12.43  12.22  12.3   12.02  12.15  12.19  12.07  12.2\n",
            "  12.19  12.68  12.88  12.74  13.    13.05  12.94  12.95  13.47  13.27\n",
            "  13.85]\n"
          ]
        }
      ],
      "execution_count": 70,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(A[:, 2:5])  # all rows, third to fifth column"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 11.02  10.98]\n",
            " [ 12.14  11.55]\n",
            " [ 12.43  12.12]\n",
            " [ 12.22  11.88]\n",
            " [ 12.3   12.28]\n",
            " [ 12.02  11.82]\n",
            " [ 12.15  11.96]\n",
            " [ 12.19  12.14]\n",
            " [ 12.07  12.02]\n",
            " [ 12.2   11.91]\n",
            " [ 12.19  12.18]\n",
            " [ 12.68  12.47]\n",
            " [ 12.88  12.59]\n",
            " [ 12.74  12.65]\n",
            " [ 13.    12.94]\n",
            " [ 13.05  12.71]\n",
            " [ 12.94  12.41]\n",
            " [ 12.95  12.95]\n",
            " [ 13.47  13.32]\n",
            " [ 13.27  12.87]\n",
            " [ 13.85  13.74]]\n"
          ]
        }
      ],
      "execution_count": 71,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "nbconvert_exporter": "python",
      "name": "python",
      "mimetype": "text/x-python",
      "file_extension": ".py",
      "version": "3.5.5",
      "pygments_lexer": "ipython3"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.28.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}